package com.kele.stream;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author chunhui.li
 * @date 2022/2/7 16:24
 * @Description
 * @ClassName StudentData
 */
public class StudentData {

    public static List<Student> getStudentList(){
        List<Student> list = new ArrayList<>();
        list.add(new Student(1,"刘备",18,90.4));
        list.add(new Student(2,"张飞",19,23.0));
        list.add(new Student(3,"关羽",21,45.5));
        list.add(new Student(4,"赵云",15,96.4));
        list.add(new Student(5,"马超",26,34.4));
        list.add(new Student(6,"曹操",17,99.4));
        list.add(new Student(7,"荀彧",16,98.7));
        list.add(new Student(8,"孙权",29,95.5));
        list.add(new Student(9,"鲁肃",26,96.7));
        list.add(new Student(9,"鲁肃",26,96.7));
        return list;
    }

    /**
     * 通过一个集合创建Stream
     */
    public void test1(){
        List<Student> studentList = StudentData.getStudentList();
        // 顺序流
        Stream<Student> stream = studentList.stream();
        // 并行流
        Stream<Student> studentStream = studentList.parallelStream();
    }

    /**
     * 使用流操作数据
     */
    @Test
    public void test2(){
        List<Student> studentList = StudentData.getStudentList();
        // 筛选年龄大于20的
        studentList.stream().filter(item->item.getAge()>20).forEach(System.out::println);
        System.out.println("======================================");
        // 筛选前三条
        studentList.stream().limit(3).forEach(System.out::println);
        System.out.println("======================================");
        // 跳过前五个
        studentList.stream().skip(5).forEach(System.out::println);
        System.out.println("======================================");
        // 过滤重复数据
        studentList.stream().distinct().forEach(System.out::println);

    }
    public void test3(){}
    public void test4(){}
    public void test5(){}

}
